package com.blue.http.config;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.blue.core.file.ClassScanner;
import com.blue.http.annotation.WebsocketClassHandler;
import com.blue.http.annotation.WebsocketParser;
import com.blue.http.server.WebsocketRouter;

/**
 * Websocket 配置
 *
 * @author zhengjin
 * @since 1.0 2018年03月18日
 */
public class WebsocketConfig implements InitializingBean, ApplicationContextAware
{
	//private static Logger logger = LoggerFactory.getLogger(WebsocketConfig.class);

	public static final String ROOT = "/ws";

	private ApplicationContext ctx;
	private List<String> packageList;
	private WebsocketRouter router;
	private WebsocketParser parser = WebsocketParser.getInstance();
	private String root = ROOT;

	public WebsocketConfig()
	{
	}

	@Override
	public void afterPropertiesSet() throws Exception
	{
		parser.setApplicationContext(ctx);
		router = new WebsocketRouter();
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
	{
		this.ctx = applicationContext;
	}

	public void setScanPackages(List<String> packageList)
	{
		this.packageList = packageList;
	}

	public void setRoot(String root)
	{
		this.root = root;
	}

	public WebsocketRouter getRouter()
	{
		return router;
	}

	public WebsocketParser getParser()
	{
		return parser;
	}

	public String getRoot()
	{
		return root;
	}
}
